package com.horay.springbootdemo.hibernate.validator.index.controller;

import com.horay.springbootdemo.common.result.ResultBody;
import com.horay.springbootdemo.hibernate.validator.groups.Update;
import com.horay.springbootdemo.hibernate.validator.index.dto.UserDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * 首页控制器
 *
 * @author heyingcheng
 * @date 2019/9/30 17:33
 */
@Slf4j
@Validated
@RestController
@RequestMapping("validator")
public class IndexController {

    @PostMapping("index")
    public ResultBody<String> index(@RequestBody @Validated UserDTO userDTO) {
        log.info("IndexController.index.UserDTO:[{}]", userDTO.toString());
        return ResultBody.RESULT_BODY_SUCCESS;
    }

    @PostMapping("groups")
    public ResultBody groups(@RequestBody @Validated(Update.class) UserDTO userDTO) {
        log.info("IndexController.groups.UserDTO:[{}]", userDTO.toString());
        return ResultBody.RESULT_BODY_SUCCESS;
    }

    @GetMapping("/get")
    public ResultBody get(@RequestParam("userId") @NotNull(message = "用户id不能为空") Long userId) {
        log.info("IndexController.get.userId:[{}]", userId);
        return ResultBody.RESULT_BODY_SUCCESS;
    }

}
